package com.wzx.user.controller;

import com.wzx.common.exception.LeadNewsException;
import com.wzx.common.pojo.resp.Result;
import com.wzx.user.dto.UserDto;
import com.wzx.user.service.UserServcie;
import com.wzx.user.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;


/**
 * @author wzx
 * @version 1.0
 * @date 2022/7/23 - 10:14
 * @description 标题
 */
@Slf4j
@RestController
@RequestMapping("/user")
@Api(tags = "用户信息管理")
public class UserController {

    @Autowired
    private UserServcie userServcie;

    @PostMapping("/updateUserInfo")
    @ApiOperation(value = "用户信息修改")
    public Result updateUserInfo(@RequestBody UserVo userVo) throws Exception {
        boolean result = userServcie.updateUserInfo(userVo);
        return Result.ok(result);
    }

    @PostMapping("/updateUserHead")
    @ApiOperation(value = "用户头像修改")
    public Result updateUserHead(MultipartFile file, long userId) throws IOException, LeadNewsException {
        String head = userServcie.updateUserHead(file,userId);
        return Result.ok(head);
    }

    @GetMapping("/getUserInfo")
    @ApiOperation(value = "用户信息查询")
    public Result<UserDto> getUserInfo(Integer userId) {
        UserDto user = userServcie.getUserInfo(userId);
        return Result.ok(user);
    }

    @GetMapping("/queryUserImgCode")
    @ApiOperation(value = "查询用户图形验证码")
    public Result<String> queryUserImgCode(String phone) {
        String imgCode = userServcie.queryUserImgCode(phone);
        return Result.ok(imgCode);
    }



}
